package com.psp.web.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.psp.web.model.ProductAttributeBean;
import com.psp.web.model.ProductBean;
import com.psp.web.model.ProductSkuBean;
import com.psp.web.persist.dao.ProductDao;

@Repository
public class ProductImpl extends BaseImpl implements ProductDao {
	protected static final String NAME_SPACE = NAME_SPACE_HEADER + ".ProductMapper";

	@Override
	public ProductBean selectById(String pid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectById", pid);
	}

	@Override
	public int selectCount(Integer firstType, Integer secType) {
		Map<String, Object> where = new HashMap<>();
		where.put("firstType", firstType);
		where.put("secType", secType);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", where);
	}

	@Override
	public List<ProductBean> selectList(Integer page, Integer pageSize, Integer firstType, Integer secType) {
		Map<String, Object> where = new HashMap<>();
		where.put("firstType", firstType);
		where.put("secType", secType);
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", where);
	}

	@Override
	public List<ProductBean> selectSimilarBs(Integer page, Integer pageSize, Integer cateCode) {
		Map<String, Object> where = new HashMap<>();
		where.put("cateCode", cateCode);
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectSimilarBs", where);
	}

	@Override
	public int selectAllCount() {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectAllCount");
	}

	@Override
	public List<ProductBean> selectAllList(Integer page, Integer pageSize) {
		Map<String, Object> where = new HashMap<>();
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectAllList", where);
	}

	@Override
	public List<ProductAttributeBean> selectAttributeList(String pid) {
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectAttributeList", pid);
	}

	@Override
	public ProductSkuBean selectProductInfoBySukCode(String skuCode) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectProductInfoBySukCode", skuCode);
	}

	@Override
	public List<ProductBean> selectByPids(Set<String> pids) {
		Map<String, Object> where = new HashMap<>();
		where.put("pids", pids);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectByPids", where);
	}

	@Override
	public List<ProductBean> selectListByCateCode(Set<Integer> cateCodes) {
		Map<String, Object> where = new HashMap<>();
		where.put("cateCodes", cateCodes);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectListByCateCode", where);
	}

}
